package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.SubjectSon;

public class SubjectSonDAOImpl extends BaseHibernateDAOImpl<SubjectSon> implements SubjectSonDAO {

	public SubjectSon getSubjectSonBySubjectSonID(String ssID) {
		SubjectSon subjectSon;
		try {
			subjectSon = (SubjectSon) getSession().get(SubjectSon.class, ssID);
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return subjectSon;
	}

	@SuppressWarnings("unchecked")
	public List<SubjectSon> getAllSubjectSon() {
		List<SubjectSon> subjectSons;
		try {
			Query query = getSession().getNamedQuery("AllSubjectSonQuery");
			subjectSons = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return subjectSons;
	}

	public SubjectSon getSubjectSonBySubjectSonName(String ssName) {
		SubjectSon subjectSon;
		try {
			Query query = getSession().getNamedQuery("SubjectSonBySubjectSonNameQuery");
			query.setString("ssName", ssName);
			subjectSon = (SubjectSon) query.uniqueResult();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return subjectSon;
	}

	public SubjectSon getSubjectSonBySubjectSonCode(String ssCode) {
		SubjectSon subjectSon;
		try {
			Query query = getSession().getNamedQuery("SubjectSonBySubjectSonCodeQuery");
			query.setString("ssCode", ssCode);
			subjectSon = (SubjectSon) query.uniqueResult();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return subjectSon;
	}
	
	@SuppressWarnings("unchecked")
	public List<SubjectSon> getAllSubjectSonBySubjectID(String subjectID) {
		List<SubjectSon> subjectSons;
		try {
			Query query = getSession().getNamedQuery("AllSubjectSonBySubjectIDQuery");
			query.setString("subjectID", subjectID);
			subjectSons = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return subjectSons;
	}


}
